package com.example.wendao.view.viewholder;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.navigation.Navigation;
import androidx.recyclerview.widget.RecyclerView;

import com.example.wendao.R;
import com.example.wendao.common.PageUtils;
import com.example.wendao.common.ViewHolderBind;
import com.example.wendao.model.entity.Forum;
import com.example.wendao.model.entity.News;

public class AgreeNewsViewHolder extends RecyclerView.ViewHolder implements ViewHolderBind<News> {

    private TextView agreeForumContent,agreeForumTitle,agreeForumAcount;
    private RelativeLayout layout;

    public AgreeNewsViewHolder(@NonNull ViewGroup viewGroup) {
        super(PageUtils.inflateItemView(viewGroup, R.layout.agree_forum_list));
        agreeForumContent = itemView.findViewById(R.id.agree_forum_content);
        agreeForumAcount=itemView.findViewById(R.id.agree_forum_acount);
        agreeForumTitle=itemView.findViewById(R.id.agree_forum_title);
        layout=itemView.findViewById(R.id.agree_forum_layout);
    }

    @Override
    public void bindTo(News news) {
        String content=news.getNewsContent().substring(0,10)+"...";
        agreeForumContent.setText( content);
        String title=news.getNewsTitle().substring(0,7)+"...";
        agreeForumTitle.setText( title);
        agreeForumAcount.setText(news.getNewsAgree());
        layout.setOnClickListener(v->{
            //传值
            Bundle bundle=new Bundle();
            bundle.putInt("forumid",news.getNewsId());
            Navigation.findNavController(v).navigate(R.id.fragment_new,bundle);
        });
    }
}
